// 飞行器类
import * as THREE from 'three'
import { BaseModel } from './BaseModel'
export class Fly extends BaseModel {
  init() {
    this.scene.add(this.model)
    this.pointIndex = 0
    this.pointArr = []
    this.isCameraMove = false
    this.generateMovePath()
  }
  generateMovePath() {
    const curve = new THREE.EllipseCurve(
      0, 0, // 椭圆中心坐标
      110, 110, // x和y轴向上椭圆的半径
      0, -2 * Math.PI, // 开始角度和扫描角度
      false, // 是否按照顺时针来绘制
      0 // 以弧度表示，椭圆从X轴正方向逆时针的旋转角度
    )
    const tempArr = curve.getPoints(10000)
    for (let i = 0; i < tempArr.length; i++) {
      let ponit = new THREE.Vector3(tempArr[i].x, 150, tempArr[i].y)
      this.pointArr.push(ponit)
    }
  }
  onTick(t) {
    if (this.pointIndex < this.pointArr.length - 1) {
      if (this.isCameraMove) {
        this.camera.position.copy(this.pointArr[this.pointIndex])
        this.camera.lookAt(0, 10, 0)
      } 
      this.model.position.copy(this.pointArr[this.pointIndex])
      this.pointIndex += 1
    } else {
      this.pointIndex = 0
      this.model.position.copy(this.pointArr[0])
    }
  }
}